package com.css.fxfzdpzs.modules.aqbz.repository.impl;

import com.css.fxfzdpzs.modules.aqbz.entity.first.*;
import com.css.fxfzdpzs.modules.aqbz.entity.second.*;
import com.css.fxfzdpzs.modules.aqbz.repository.AqbzRepository;
import com.css.fxfzdpzs.modules.aqbz.vo.AbMapDateEntity;
import com.css.fxfzdpzs.util.PlatformObjectUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author y1fan
 * @description
 */
@Repository
public class AqbzRepositoryImpl implements AqbzRepository {

    @Resource
    JdbcTemplate jdbcTemplate;

    @Resource
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public List<AbActivityEvent> getActivityEvent() {
        String sql = "select * from ab_activity_event ";
        List<AbActivityEvent> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbActivityEvent.class));
        return list;
    }

    @Override
    public List<AbActivityNumStatistics> getAbActivityNumStatistic() {
        String sql = "select * from ab_activity_num_statistics order by activity_years ";
        List<AbActivityNumStatistics> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbActivityNumStatistics.class));
        return list;
    }
    @Override
    public List<AbPlaceHotList> getPlaceHotList() {
        String sql = "select * from ab_place_hot_list ";
        List<AbPlaceHotList> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbPlaceHotList.class));
        return list;
    }

    @Override
    public List<AbProvinceActivationRank> getAbProvinecActivationRank() {
        String sql = "select * from ab_province_activation_rank ";
        List<AbProvinceActivationRank> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbProvinceActivationRank.class));
        return list;
    }

    @Override
    public AbSystemAchievementsStatistics getAbSystemAchievementsStatistics() {
        String sql = "select * from ab_system_achievements_statistics ";
        List<AbSystemAchievementsStatistics> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbSystemAchievementsStatistics.class));
        if (PlatformObjectUtils.isEmpty(list)){
            return null;
        }else {
            return list.get(0);
        }

    }

    @Override
    public AbSystemYseSituation getAbSystemYseSituation() {
        String sql = "select * from ab_system_use_situation ";
        List<AbSystemYseSituation> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbSystemYseSituation.class));
        if (PlatformObjectUtils.isEmpty(list)){
            return null;
        }else {
            return list.get(0);
        }
    }

    @Override
    public List<AbRiskDangerPoints> getAbRiskDangerPoints(String iaId) {
        String sql = "select * from ab_risk_danger_points where ia_id='"+iaId+"' ";
        List<AbRiskDangerPoints> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbRiskDangerPoints.class));
        return list;
    }

    @Override
    public AbReport getReport(String iaId) {
        String sql = "select * from ab_report ";
        List<AbReport> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbReport.class));
        if (PlatformObjectUtils.isEmpty(list)){
            return null;
        }else {
            return list.get(0);
        }
    }

    @Override
    public List<AbTujian> getTjzs(String iaId) {
        String sql = "select * from ab_tujian where ia_id='"+iaId+"' ";
        List<AbTujian> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbTujian.class));
        return list;
    }

    @Override
    public List<AbKeySite> getZdcs(String iaId) {
        String sql = "select  *  from ab_zdcs   WHERE ia_id='"+iaId+"'";
        List<AbKeySite> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbKeySite.class));
        return list;
    }

    @Override
    public List<AbLittleZdcs> getLittleZdcs(String zdcsId) {
        String sql = "select  *  from ab_zdcs_little   WHERE zdcs_id='"+zdcsId+"'";
        List<AbLittleZdcs> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbLittleZdcs.class));
        return list;
    }

    @Override
    public List<AbMapDateEntity> getMapDate(String type) {
        String sql=null;
        if (type.equals("0")){
            sql = "select a.type,b.lon_s as longitude,b.lat_s as latitude,b.province_code from ( SELECT type ,province  FROM ab_map_date where 1=1  and  type='"+type+"' group by province,type) a  left join dzzh_map_dict b on a.province=b.province_code";
        }else {
            sql = "select a.type,b.lon as longitude,b.lat as latitude,b.province_code from ( SELECT type ,province  FROM ab_map_date where 1=1  and  type='"+type+"' group by province,type) a  left join dzzh_map_dict b on a.province=b.province_code";
        }
        List<AbMapDateEntity> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbMapDateEntity.class));
        return list;
    }

    @Override
    public List<AbMapDate> getIa(String provinceCode, String type) {
        String sql = "select  *  from ab_map_date   WHERE province='"+provinceCode+"' and type='"+type+"'";
        List<AbMapDate> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(AbMapDate.class));
        return list;
    }

    @Override
    public List<String> getSiteName() {
        String sql="select DISTINCT(ss_jzwmc) from  ab_sys_site where del_flag ='0'";
        List<String> list=jdbcTemplate.queryForList(sql,String.class);
        return list;
    }

    @Override
    public Integer getPlaceNumBySiteName(String siteName) {
        String sql="select count(*) from  ab_map_date where ia_zdmb like '&"+siteName+"&' ";
        Integer num=jdbcTemplate.queryForObject(sql,Integer.class);
        return num;
    }


}
